from kivy.properties import BooleanProperty, ObjectProperty, ListProperty, NumericProperty, StringProperty
from kivy.uix.spinner import Spinner

from kivy_cust.ButtonComm import ButtonComm
from kivy_cust.ConfigComm import ConfigComm


class SpinnerOptionComm(ButtonComm):
    color = ListProperty((0, 0, 0, 1))
    font_size = NumericProperty(16)
    background_normal = (ConfigComm.IMG_BUTTON_COMM_OPTION)  # 按钮未点击时背景图
    background_down = (ConfigComm.IMG_BUTTON_COMM_PRESSED)  # 按钮未点击时背景图

    def __init__(self, **kwargs):
        super(SpinnerOptionComm, self).__init__(**kwargs)
        self.size_hint = (1, None)
        self.height = 35


class SpinnerComm(Spinner):
    color = ListProperty((0, 0, 0, 1))
    option_cls = ObjectProperty(SpinnerOptionComm)
    sync_height = BooleanProperty(True)  # 不设置sync_height时 height不会应用到下拉框里
    background_normal = StringProperty(ConfigComm.IMG_BUTTON_COMM_FORM)
    background_down = StringProperty(ConfigComm.IMG_BUTTON_COMM_FORM)

    def __init__(self, **kwargs):
        super(SpinnerComm, self).__init__(**kwargs)
        self.size_hint_y = None
        self.height = 30
        self.pos_hint = {"center_x": 0, "center_y": 0.5}


